package com.bingxue.edu.management.shop.model.resp;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.enums.BooleanEnum;
import com.bingxue.edu.framework.excel.converter.ExcelListNewLineConverter;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author panbo
 * @since 2024/11/28
 */
@Data
public class PayRecordExportResp {

    @ColumnWidth(28)
    @ExcelProperty(value = "订单编号")
    private String id;

    @ColumnWidth(24)
    @ExcelProperty(value = "付款时间")
    private LocalDateTime payTime;

    @ExcelProperty(value = "学生姓名")
    private String studentName;

    @ColumnWidth(16)
    @ExcelProperty(value = "家长电话")
    private String parentPhone;

    @ColumnWidth(66)
    @ContentStyle(wrapped = BooleanEnum.TRUE)
    @ExcelProperty(value = "购课班级", converter = ExcelListNewLineConverter.class)
    private List<String> orderItemList;

    @ExcelProperty(value = "原价")
    private BigDecimal originalTotalPrice;

    @ExcelProperty(value = "优惠")
    private BigDecimal discountTotalPrice;

    @ExcelProperty(value = "实收")
    private BigDecimal actualTotalPrice;

    @ExcelProperty(value = "收款账户")
    private String finAccountName;

    @ExcelProperty(value = "三方账户")
    private String outTradeNo;

    @ExcelProperty(value = "创建人")
    private String createUserName;

    public static PayRecordExportResp of(PayRecordListResp from) {
        PayRecordExportResp resp = new PayRecordExportResp();
        resp.setId(from.getId());
        resp.setPayTime(from.getPayTime());
        resp.setStudentName(from.getStudent().getName());
        resp.setParentPhone(from.getStudent().getParentPhone());
        resp.setOrderItemList(from.getOrderItemList().stream().map(item -> String.format(String.format("【%d节】%s", item.getLessonIndexes().size(), item.getClassName()))).toList());
        resp.setOriginalTotalPrice(from.getOriginalTotalPrice());
        resp.setDiscountTotalPrice(from.getDiscountTotalPrice());
        resp.setActualTotalPrice(from.getActualTotalPrice());
        resp.setFinAccountName(from.getFinAccount().getName());
        resp.setOutTradeNo(from.getOutTradeNo());
        resp.setCreateUserName(from.getCreateUserName());
        return resp;
    }
}
